package hmvictor.jpql.nodes;

import hmvictor.jpql.Connection;
import hmvictor.jpql.ConnectionDialog;
import hmvictor.jpql.ConnectionsTopComponent;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import org.openide.windows.WindowManager;

/**
 *
 * @author Victor
 */
public class AddConnectionAction extends AbstractAction {

    public AddConnectionAction() {
        super("Add Connection");
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        Connection connection=null;
        ConnectionsTopComponent c=(ConnectionsTopComponent) WindowManager.getDefault().findTopComponent("ConnectionsTopComponent");
        if ((connection = ConnectionDialog.showNewDialog(WindowManager.getDefault().getMainWindow(), c.getConnectionNames())) != null) {
            c.addConnection(connection);
//            JPQLEditorTopComponent topComponent = (JPQLEditorTopComponent) WindowManager.getDefault().findTopComponent("JQPLEditorTopComponent");
//            topComponent.setConnections(getConnections());
//            try {
//                saveConnections();
//            } catch (IOException | XMLStreamException ex) {
//                Exceptions.printStackTrace(ex);
//            }
        }
    }

}
